from logging import getLogger

from meercat.mapreduce.mappers.xsl import XslMapper



log = getLogger('meercat.server.rest.mapreduce')

class WebXslMapper(XslMapper):
    def post_transform(self, metadata, element):
        instance = metadata.getInstance()
        
        if instance is None:
            log.warning('Metadata object without an instance')
            return
        
        for ielement in element.findall('instance'):
            log.debug('Setting id, source and last-modified on instance')
            ielement.set('id', str(instance.getIdentifier()))
            ielement.set('source', str(instance.getSource()))
            ielement.set('last-modified', str(instance.getLastModified()))
        
        resource = instance.getResource()
        
        if resource is None:
            log.warning('Instance object without a resource')
            return
        
        for relement in element.findall('resource'):
            log.debug('Setting id on resource')
            relement.set('id',str(resource.getIdentifier()))
        
        
        